# -*- coding:utf-8 -*-
# timeout-访问超时
# 设置访问超时，一旦超过设置时间，则会抛出异常
# 通常用来检测代理ip的可用性

import requests

# 发起目标请求的网站
url = "https://www.baidu.com"

# 添加伪装
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
}


# 向目标网站发起请求
response = requests.get(url, headers=headers, timeout=0.1)
response.encoding = "utf-8"

print(response.text)


# 如果ip地址陷入黑名单，构建代理池写法
# def get_data():
#     try:
#         response = requests.get(url, headers=headers, timeout=0.01)
#
#         # 解决文件中的乱码
#         response.encoding = "utf-8"
#
#     except:
#         return get_data()
